package view.shop
{
import core.manager.RequirementManager;
import core.manager.ShopManager;

import flash.text.TextField;

import framework.view.components.button.ButtonProxy;

import values.other.ConditionValue;
import values.shop.ShopItemValue;

/**
 * ShopItemBuyerProxy
 * @author jliang
 *
 */
public class ShopItemBuyerProxy extends ShopItemHandlerProxy
{
    //==========================================================================
    //  Constructor
    //==========================================================================
    public function ShopItemBuyerProxy()
    {
        super();
    }
    //==========================================================================
    //  Variables
    //==========================================================================
    protected function get conditionLabel():TextField
    {
        return skin.conditionLabel;
    }
    
    protected function get buyBtn():ButtonProxy
    {
        return proxys["buyBtn"];
    }
    //==========================================================================
    //  Overridden methods: AssetItemRenderProxy
    //==========================================================================
    protected var _data:ShopItemValue;
    
    public function set data(value:ShopItemValue):void
    {
        _data = value;
    }
    
    public function get data():ShopItemValue
    {
        return _data;
    }
    
    override protected function get proxyMapping():Array
    {
        return [ 
            { skin:"buyBtn", classRef: ButtonProxy, id:"buyBtn", onClick: onClickToBuyHandler }
        ];
    }
    //==========================================================================
    //  Public methods
    //==========================================================================
    public function check():void
    {
        //check requirement
        var con:ConditionValue = RequirementManager.checkItemBuyRequirement(data);
        
        conditionLabel.visible = !con.isReached;
        buyBtn.visible = con.isReached;
        
        conditionLabel.text = con.desc;
    }
    //==========================================================================
    //  Event handlers
    //==========================================================================
    protected function onClickToBuyHandler():void
    {
        ShopManager.requestToBuy(data);
    }
}
}



